package com.lfnyxy.service.imp;

import com.lfnyxy.dao.PolicyDao;
import com.lfnyxy.entity.PolicyEntity;
import com.lfnyxy.query.PolicyQuery;
import com.lfnyxy.service.PolicyService;
import com.lfnyxy.vo.NewsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PolicyServiceImp implements PolicyService {
    @Autowired
    public PolicyDao policyDao;

    public int CreateItem(PolicyEntity entity) {
        if (entity != null) {
            return policyDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(PolicyEntity entity) {
        if (entity != null) {
            return policyDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List <NewsVo> QueryPageList(PolicyQuery query) {
        int count = policyDao.QueryPageListCount(query);
        query.setTotal(count);
        return policyDao.QueryPageList(query);
    }

    public List <PolicyEntity> QueryAll() {
        return policyDao.QueryAll();
    }

    public PolicyEntity QueryItem(int Id) {
        if (Id > 0) {
            return policyDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return policyDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(PolicyEntity entity) {
        if (entity != null) {
            return policyDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}